<template>
	<view class="msglist">
		<view v-for="(item,index) in list" :key="index" @click="go_news(item)" class="list">
			<image :src="item.image" mode="aspectFill">
				<view class="text">
					<view class="title">
						{{item.title}}
					</view>
					<view class="describe">
						<view class="time">
							<image src="/static/img/time.png" />{{item.pubTime}}</view>
						<!-- <view class="see">
							<image src="/static/img/see.png" />{{item.hits}}</view> -->
					</view>
				</view>
		</view>
		<view v-if="list.length==0" class="notavailable">
			<image src="../../../static/img/notavailable.png" mode="widthFix"></image>
			<view class="nottext">暂时没有数据</view>
		</view>
		<view class="pagination">
			<view class="left" :class="{ forbid: paging.page == 1 }" @click="prev">
				<uni-icons type="arrowleft" size="20" color="#fff" class="icons" />
				上一页
			</view>
			<view class="center">{{ paging.page }}/{{ paging.total }}</view>
			<view class="right" :class="{ forbid: paging.page == paging.total }" @click="next">
				下一页
				<uni-icons type="arrowright" size="20" color="#fff" class="icons" />
			</view>
		</view>
	</view>
</template>
<script>
	import {
		uniIcons
	} from '@dcloudio/uni-ui';
	import news from '../../../servers/shop/news.js'
	export default {
		data() {
			return {
				list: [],
				type: '',
				paging: {
					page: 1,
					total: 10
				}
			}
		},
		mounted() {
			this.type = uni.getStorageSync('go_morenews') || this.$route.query.go_morenews
			this.getData(this.type)

		},
		methods: {
			getData(e) {
				var obj = {
					currentPage: this.paging.page,
					pageSize: 10
				}
				news.newslistBytype(obj, e).then(res => {
					this.paging.total = Math.ceil(res.data.total / res.data.size);
					this.list = res.data.records.map(v => {
						v.image = this.imgCDNUrl + v.img
						return v
					})
				}).catch(err => {
					console.log(new Error('请检查网络后重试'))
				})
			},
			go_news(e) {
				this.commonality.route_baling('/pages/shop/news/news', 'shopnewsnews', e.id)
			},
			next() {
				if (this.paging.page < this.paging.total) {
					this.paging.page += 1;
					this.getData(this.type);
				}
			},
			prev() {
				if (this.paging.page > 1) {
					this.paging.page -= 1;
					this.getData(this.type);
				}
			}
		}
	}
</script>
<style lang="less" scoped>
	.msglist {
		position: relative;
		height: 100%;

		.list {
			position: relative;
			padding: 20rpx;
			display: block;
			overflow: hidden;
			border-bottom: 1rpx solid #e1e1e1;
			/*no*/
			background: #fff;

			image {
				width: 260rpx;
				height: 217rpx;
				float: left;
				margin-right: 25rpx;
			}

			.title {
				font-size: 28rpx;
				line-height: 40rpx;
			}

			.describe {
				position: absolute;
				bottom: 20rpx;
				left: 293rpx;
				right: 20rpx;
				font-size: 26rpx;

				view {
					display: inline-block;
					line-height: 32rpx;

					image {
						width: 43rpx;
						height: 32rpx;
						margin-right: 5rpx;
					}
				}

				.see {
					position: absolute;
					right: 0;
					top: 5rpx;
				}
			}

		}
	}
</style>
